package cn.gh.duboo.demo.service.impl;

import cn.gh.duboo.demo.model.Blog;
import cn.gh.duboo.demo.service.BlogService;
import com.jfinal.plugin.activerecord.Page;

/**
 * Created by Administrator on 2015/9/17.
 */
public class BlogServiceImpl implements BlogService {

    private Blog blogDao;

    public Page<Blog> paginate(int pageNumber, int pageSize) {
        return blogDao.paginate(pageNumber, pageSize, "select *", "from blog order by id asc");
    }

//    更新
    public void update(Blog blog) {
        if (blog == null) {
            return;
        }
        blog.update();
    }
//    新增
    public Blog save(Blog blog) {
        if (blog == null) {
            return null;
        }
        blog.save();
        return blog;
    }
//    查找
    public Blog findById(String id) {
        Blog blog = blogDao.findById(id);
        return blog;
    }
//    删除
    public void deleteById(String id) {
        blogDao.deleteById(id);
    }

    /**
     * 通过Spring配置文件注入Blog的dao
     * @param blogDao
     */
    public void setBlogDao(Blog blogDao) {
        this.blogDao = blogDao;
    }
}
